﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using DevExpress.AgDataGrid;
using System.Windows.Controls;
using DevExpress.AgDataGrid.Internal;
using System.Windows;
using System.Windows.Controls.Primitives;
using DevExpress.AgDataGrid.Data;
using System.Windows.Shapes;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace DevExpress.AgDataGrid.Tests {
	public class Customer {
		int id;
		string name;
		public int Id { get { return id; } }
		public string Name { get { return name; } set { name = value; } }
		public string Group { get; set; }
		public DateTime BirthDate { get; set; }
		public decimal Salary { get; set; }
		public const int ColumnsCount = 5;
		public Customer(int id, string name, string group, DateTime birthDate, decimal salary) {
			this.id = id;
			this.name = name;
			this.Group = group;
			this.BirthDate = birthDate;
			this.Salary = salary;
		}
	}
	public static class TestDataGridHelper {
		static public AgDataGrid CreateGrid() {
			return CreateGrid(10);
		}
		static public AgDataGrid CreateGrid(int rowCount) {
			AgDataGrid grid = new AgDataGrid();
			grid.DataSource = CreateCustomersList(rowCount);
			return grid;
		}
		public static List<Customer> CreateCustomersList(int count) {
			List<Customer> result = new List<Customer>();
			for (int i = 0; i < count; i++)
				result.Add(new Customer(i, "Customer " + i.ToString(), "Group " + (i % 4).ToString(),
					new DateTime(1960 + i % 20, 1 + i % 11, 1 + i % 27), i * 1000));
			return result;
		}
		static object GetValue(this object obj, string propName) {
			PropertyInfo prop = obj.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.NonPublic);
			if (prop == null) throw new ArgumentException(propName + " property was not found in the " + obj.GetType().Name + " class!");
			return prop.GetValue(obj, null);
		}
		public static Canvas GetDataPanelClipper(this AgDataGrid grid) {
			return (Canvas)grid.GetValue("DataPanelClipper");
		}
		public static Panel GetDataPanel(this AgDataGrid grid) {
			return (Panel)grid.GetValue("DataPanel");
		}
		public static Canvas GetTotalPanel(this AgDataGrid grid) {
			return (Canvas)grid.GetValue("TotalPanel");
		}
		public static Panel GetGroupPanel(this AgDataGrid grid) {
			return (Panel)grid.GetValue("GroupPanel");
		}
		public static Panel GetHeadersPanel(this AgDataGrid grid) {
			return (Panel)grid.GetValue("HeadersPanel");
		}
		public static ScrollBar GetHorizontalScrollBar(this AgDataGrid grid) {
			return (ScrollBar)grid.GetValue("HorizontalScrollBar");
		}
		public static ScrollBar GetVerticalScrollBar(this AgDataGrid grid) {
			return (ScrollBar)grid.GetValue("VerticalScrollBar");
		}
		public static UIElement GetBottomRightCorner(this AgDataGrid grid) {
			return (UIElement)grid.GetValue("BottomRightCorner");
		}
		public static bool IsTemplatesLoaded(this AgDataGrid grid) {
			return grid.GetDataPanelClipper() != null;
		}
		public static double GetExpectedDataPanelHeight(this AgDataGrid grid) {
			return grid.ActualHeight - grid.GetGroupPanel().ActualHeight - grid.GetHeadersPanel().ActualHeight - grid.GetTotalPanel().ActualHeight - 7;
		}
		public static int GetTopRow(this AgDataGrid grid) {
			return grid.TopRow;
		}
		public static FrameworkElement GetCurrentEditor(this AgDataGrid grid) {
			return grid.CurrentEditor;
		}
	}
}
